//
//  MainTabBarViewController.swift
//  XiaoXiangMu1604
//
//  Created by qianfeng on 16/9/26.
//  Copyright © 2016年 SunPiaoLiang. All rights reserved.
//

import UIKit

class MainTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //创建子视图控制器
        createViewController()
        
        //设置TabBar字体的颜色
        tabBar.tintColor = UIColor(red: 83.0/255.0, green: 156.0/255.0, blue: 255.0/255.0, alpha: 1.0)
        
        //统一设置某些控件的显示特性
        //UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blackColor()], forState: .Selected)
        
    }
    func createViewController(){
        
        //标题
        let titleArray = ["限免","降价","免费","专题","热榜"]
        
        //图片
        let imageArray = ["tabbar_limitfree","tabbar_reduceprice","tabbar_appfree","tabbar_subject","tabbar_rank"]
        
        //视图控制器
        let ctlArray = ["XiaoXiangMu1604.LimitFreeViewController","XiaoXiangMu1604.ReduceViewController","XiaoXiangMu1604.FreeViewController","XiaoXiangMu1604.SubjectViewController","XiaoXiangMu1604.RankViewController"]
        
        //设一个导航控制器的数组
        var array = Array<UINavigationController>()
        
        for i in 0..<titleArray.count{
            
            let ctlName = ctlArray[i]
            
            let cls = NSClassFromString(ctlName) as! UIViewController.Type
            
            let ctrl = cls.init()
            
            //文字
            ctrl.tabBarItem.title = titleArray[i]
            
            let imageName = imageArray[i]
            
            //图片
            ctrl.tabBarItem.image = UIImage(named: imageName)
            
            //选中的图片
            ctrl.tabBarItem.selectedImage = UIImage(named: imageName + "_press")?.imageWithRenderingMode(.AlwaysOriginal)
            
            //添加导航
            let navCtrl = UINavigationController(rootViewController: ctrl)
            
            //将导航加到数组中
            array.append(navCtrl)
        }
        
        viewControllers = array
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
